package com.qf.aspect;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.stereotype.Component;

@Component
@Aspect
public class MyAspect {
    //前置增强
    //@Before("execution(* com.qf.service.impl.*.*(..))")
    public void myBefore(JoinPoint joinPoint){
        System.out.println("方法执行前");
        System.out.println("目标方法名"+joinPoint.getSignature().getName());

    }
    //后置增强
    //@After("execution(* com.qf.service.impl.*.*(..))")
    public void myAfter(JoinPoint joinPoint){
        System.out.println("方法执行后");
        String name = joinPoint.getSignature().getName();
        System.out.println("目标方法"+name);
    }
    //环绕通知
    @Around("execution(* com.qf.service.impl.*.*(..))")
    public  void around(ProceedingJoinPoint joinPoint){
        System.out.println("环绕通知前");
        try{
            Object proceed = joinPoint.proceed();
            System.out.println("环绕通知后，提交事务");
        }catch(Throwable e){
            System.out.println("环绕通知后，回滚事务");
        }
    }
}
